
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
export default {
  namespaced: true,
  state: {
    userInfo: {
      nickname: userInfo.nickname || '',
      username:  userInfo.username || '',
      id:  userInfo.id || '',
      avatar:  userInfo.avatar || '',
      role: userInfo.role || null,
    },
    token: localStorage.getItem('token') || null
  },
  mutations: {
    setUserInfo(state, payload) {
      state.userInfo = payload.userInfo;
      state.token = payload.token
    }
  }
}